﻿using System;
using System.Linq;
using Pap.Data;
using Pap.Web.Utils;

namespace Pap.Web.Modules.Loan.ViewModel
{
    /// <summary>
    /// 
    /// </summary>
    public class TodayExecutedLoansControlViewModel : IViewModel
    {
        /// <summary>
        /// 
        /// </summary>
        ILoanRepository _LoanRepository;
        /// <summary>
        /// Initializes a new instance of the <see cref="TodayExecutedLoansControlViewModel"/> class.
        /// </summary>
        /// <param name="loanRepository">The loan repository.</param>
        public TodayExecutedLoansControlViewModel(ILoanRepository loanRepository)
        {
            _LoanRepository = loanRepository;
        }

        /// <summary>
        /// Gets the todays executed loans.
        /// </summary>
        /// <returns></returns>
        public object GetTodaysExecutedLoans()
        {
            var todayExecutions = _LoanRepository.FindLoanExecutions(loanEx => loanEx.ExecutionDate.Date == DateTime.Today.Date);
            return (from exec in todayExecutions
                    select new
                    {
                        LoanNumber = exec.CustomerLoan.LoanNumber,
                        CustomerName = exec.CustomerLoan.CustomerObj.CustomerName,
                        LoanPaymentMethod = exec.PaymentMethodObj.LoanPaymentMethodName,
                        LoanAmount = exec.LoanAmount,
                        LoanPaymentPeriod = exec.LoanPeriod
                    });
        }
    }
}
